<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019-02-25
  Time: 14:54
--%>
<html>
<head>
    <script type="text/javascript" src=".././static/js/public-head.js"></script>
</head>
<body>

<form class="layui-form" action="javascript:;" lay-filter="rpt-form"  >
    <input type="hidden" lay-submit lay-filter="down2007">
    <div id="page-header">

    </div>
</form>

<hr>
<div class="layui-fluid" id="page-body" >
</div>
</body>
<script type="text/javascript" src="js/report.js"></script>
<script type="text/javascript">
    layui.config({
        base: basePath+'/layui/lay/modules/'
    }).extend({
        formSelects: 'formSelects-v4'
    }).use([ 'table','form','formSelects' ,'element','laydate' ,'upload' ], function() {
        var $ = layui.$;
        var form = layui.form;
        var formSelects = layui.formSelects;
        var layer = layui.layer;
        var table = layui.table;
        var element = layui.element;
        var laydate = layui.laydate;
        var layindex;
        var upload = layui.upload

        //获取rpt基本配置
        $.getJSON(basePath+"/xdWidgetReport/getOne"+urlParam, function (rstHtml) {
            if(rstHtml.code!=0){
                layer.msg(rstHtml.msg)
            }else{
                $("#page-header").append(rstHtml.data.pageHeader)
                $("#page-body").append(rstHtml.data.pageBody)
                $("#page-header .layui-form-item").append('<div class="layui-inline"><button class=layui-btn lay-submit  id=rpt-query  lay-filter=rpt-query>查询</button></div>')
                //解析查询条件
                $.getJSON(basePath+"/xdWidgetReport/getRptBusinessCfgAct"+urlParam,function(rst){

                    if(rst.code !=0){
                        layer.alert("异常:<br>"+rst.msg,{icon:2})
                        return
                    }

                    //二阶参数传值
                    var where = rst.where

                    var allSelect = {} //所有的select
                    var eventMap = {}
                    var selectValue = {}
                    $.each(rst.formItem,function(index,item){
                        if(item.classFlag == "xd-date"){
                            laydate.render({elem:"#"+item.name,type:item.type,value: new Date(where[item.name]||commonUtil.setDefaultDate(item.defaultValue)),theme:item.theme})
                        }else if(item.classFlag =="xd-select" ){
                            ///////////...........缺少select赋值.....................
                            allSelect[item.name] = item
                            if(item.events!=null && item.events !== ""){
                                eventMap[item.name] = item
                            }
                            selectValue[item.name] =  where[item.name]
                        }else{
                            var itemValue = {}
                            itemValue[item.name] = where[item.name]
                            form.val("rpt-form",itemValue)
                        }
                    })

                    //初始化级select,以及级联事件
                    reportModelUtil.initSelect(formSelects,allSelect,eventMap,selectValue)
                    reportModelUtil.initTable(form,table,rst.table,upload,where)

                })
            }
        })

    })

</script>
</html>